package com.wei.controller;


import com.wei.entity.GdFee;
import com.wei.entity.GdWaterfee;
import com.wei.mapper.GdFeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李泽伟
 * @since 2022-03-08
 */
@RestController
@RequestMapping
public class GdFeeController {

    @Autowired
    private GdFeeMapper feeMapper;

    @RequestMapping("/getFee")
    public List<GdFee> getFee(){
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        return feeMapper.selectByMap(map);
    }

    @RequestMapping("/addFee")
    public void addFee(@RequestParam Map<String,Object> feeObj){
        GdFee fee =setParam(feeObj);
        feeMapper.insert(fee);
    }

    @RequestMapping("/updateFee")
    public void updateFee(@RequestParam Map<String,Object> feeObj){
        GdFee fee = setParam(feeObj);
        feeMapper.updateById(fee);
    }

    @RequestMapping("/deleteFee")
    public void deleteFee(@RequestParam String feeId){
        feeMapper.deleteById(feeId);
    }

    /**
     * 通过房产地址获取月度账单记录，用于账单的查询(普通用户)
     * @param address
     * @return
     */
    @RequestMapping("/getfeeByAddress")
    public List<GdFee> getfeeByAddress(@RequestParam String address){
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        map.put("property_address", address);
        return feeMapper.selectByMap(map);
    }

    /**
     * 设置参数方法
     * @param feeObj
     * @return
     */
    private GdFee setParam(@RequestParam Map<String, Object> feeObj) {
        GdFee fee=new GdFee();
        fee.setFeeId((String) feeObj.get("feeId"));
        fee.setFeeForeignkey((String) feeObj.get("feeForeignkey"));
        fee.setFeeDate((String) feeObj.get("feeDate"));
        fee.setFeeEnddate((String) feeObj.get("feeEnddate"));
        fee.setFeeStatus((String) feeObj.get("feeStatus"));
        fee.setFeeWaterid((String) feeObj.get("feeWaterid"));
        fee.setFeeElectricityid((String) feeObj.get("feeElectricityid"));
        fee.setFeeGasid((String) feeObj.get("feeGasid"));
        fee.setFeeManagefee( Integer.parseInt(feeObj.get("feeManagefee").toString()));
        fee.setFeeTotal(Integer.parseInt(feeObj.get("feeTotal").toString()));
        fee.setPropertyAddress((String) feeObj.get("propertyAddress"));
        fee.setWaterfee( Integer.parseInt(feeObj.get("waterfee").toString()));
        fee.setElectricityfee(Integer.parseInt(feeObj.get("electricityfee").toString()));
        fee.setGasfee( Integer.parseInt(feeObj.get("gasfee").toString()));
        return fee;
    }

}

